// 导入封装好的网络请求文件
import { GET, POST, DELETE } from 'utils/request';

// ========================================= Home =========================================
// 获取首页轮播图与推荐数据
export const getHomeMultidata = () => GET('/home/multidata');

// 获取首页商品数据
export const getHomeGoods = (params) => GET('/home/data', params);

// 根据iid >>> 获取详情页数据
export const getDetail = (params) => GET('/detail', params);

// 获取详情页推荐数据
export const getRecommend = () => GET('recommend');


// 详情页基本信息封装类 >>> 供详情页使用
export class Goods {
  // 构造器: 传入参数
  constructor(itemInfo, columns, services) {
    this.title = itemInfo.title;
    this.desc = itemInfo.desc;
    this.oldPrice = itemInfo.oldPrice;
    this.newPrice = itemInfo.price;
    this.discount = itemInfo.discountDesc;
    this.discountBgColor = itemInfo.discountBgColor;
    this.columns = columns;
    this.services = services;
    // 购物车所需的真实价格
    this.realPrice = itemInfo.lowNowPrice;
  }
}

// 详情页店铺信息封装类 >>> 供详情页使用
export class Shops {
  constructor(shopInfo) {
    // 对象的解构赋值
    let { shopLogo, name, cFans, cSells, score, cGoods } = shopInfo;
    this.logo = shopLogo;
    this.name = name;
    this.fans = cFans;
    this.sells = cSells;
    this.score = score;
    this.goodsCount = cGoods;
  }
}

// 详情页参数信息封装类 >>> 供详情页使用
export class GoodParams {
  constructor(info, rule) {
    // 注: images可能会没有值(某些商品有, 某些商品没有)
    this.images = info.images ? info.images[0] : '';
    this.infos = info.set;
    this.sizes = rule.tables;
  }
}